<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>demo</title>
    <meta charset="UTF-8">

    <script src="javascript/elasticsearch.js"></script>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

    <script>
        $(function () {
            $('#q').click(function () {
                var q = new ElasticSearch().getQueryBody($('#search_text').val());
                q.setStartIndex(0);//page index
                q.setTypes(['user']);//添加doc type的过滤条件
                q.setRange('@timestamp', '2017-07-19', '2017-07-20'); //添加过滤时间
                console.log(q.toString());

                // 注意，需要在elasticsearch中开通跨域CROS才能成功。
                $.ajax({
                    url: 'http://127.0.0.1:9200/myIndex/_search',
                    type: 'post',
                    dataType: 'json',
                    data: q.toString()
                }).done(function (data) {
                    $('#result').text(JSON.stringify(data));
                });
            });
        })
    </script>
</head>
<body>
<section>
    <label for="search_text">查询条件</label><input name="search_text" size="30" id="search_text"/>
    <button id="q">查询</button>
</section>
<article id="result">

</article>
</body>
</html>